package com.lizard.schedule.persistence.sharedpreferences;

import android.content.Context;
import android.content.SharedPreferences;

import com.lizard.schedule.ScheduleApplication;

/**
 * 通用SharedPreference
 */
public class CommonPref {

    private static CommonPref instance;

    /**
     * pref文件名
     */
    private final static String PREF_NAME = "pref_c";

    /**
     * 最近一次首页提示更新时间
     */
    private final static String PARAM_LAST_UPGRADE_ALERT_TIME = "p_a";

    private SharedPreferences mPref;

    private CommonPref(){
        mPref = ScheduleApplication.applicationContext
                .getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }

    public static CommonPref getInstance(){
        if(instance == null){
            synchronized (CommonPref.class){
                if(instance == null){
                    instance = new CommonPref();
                }
            }
        }
        return instance;
    }

    /**
     * 记录最近一次首页提示更新时间
     *
     * @param time
     */
    public void setLastUpgradeAlertTime(long time){
        SharedPreferences.Editor editor = mPref.edit();
        editor.putLong(PARAM_LAST_UPGRADE_ALERT_TIME, time);
        editor.commit();
    }

    /**
     * 获取最近一次首页提示更新时间
     *
     * @return
     */
    public long getlastUpgradeAlertTime(){
        return mPref.getLong(PARAM_LAST_UPGRADE_ALERT_TIME, 0);
    }

}
